import paramiko
from scp import SCPClient


def download_file_from_server(hostname, port, username, password, remote_file_path, local_file_path):
    try:
        # 创建 SSH 客户端
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        # 连接到远程服务器
        ssh.connect(hostname, port=port, username=username, password=password)

        # 使用 SCP 从服务器下载文件
        with SCPClient(ssh.get_transport()) as scp:
            scp.get(remote_file_path, local_file_path)

        return (True, f"文件成功下载到 {local_file_path}")

    except Exception as e:
        
        return(False, f"文件下载失败，错误信息：{e}")

    finally:
        ssh.close()
